<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
if (!function_exists('debugtxt')) {
    /**
     * @title 测试输出方法
     * @description 测试输出方法
     * @author Admin ldy
     * @param name:email  type:string require:1 default:1 desc:
     * @time 2018/9/21  15:17
     * @throws HttpException
     * @throws HttpResponseException
     */
    function debugtxt($content, $path = 'F:\phpStudy\WWW\ayu\test\\')
    {
        debugtxtbase($content,time(),$path);
    }
}

if (!function_exists('kh')) {
    /**
     * @title 测试输出方法
     * @description 测试输出方法
     * @author Admin ldy
     * @param name:email  type:string require:1 default:1 desc:
     * @param string $path
     * @time 2018/9/21  15:17
     */
    function kh($content, $path = 'F:\phpStudy\WWW\ayu\test\debug\\')
    {
        debugtxtbaseonefile($content,'01',$path);
    }
}
if (!function_exists('khclear')) {
    /**
     * @title 测试输出方法
     * @description 测试输出方法
     * @author Admin ldy
     * @param string $path
     * @time 2018/9/21  15:17
     */
    function khclear($path = 'F:\phpStudy\WWW\ayu\test\debug\\')
    {
        $redis = \app\common\library\Sign::getRedis();
        $key = '01.txt';
        $redis->set($key,'');
    }
}

if (!function_exists('debugtxtbaseonefile')) {
    /**
     * @title 测试输出方法
     * @description 测试输出方法
     * @author Admin ldy
     * @param $content
     * @param $name
     * @param string $path
     * @time 2018/9/25  9:57
     */
    function debugtxtbaseonefile($content,$name,$path = 'F:\phpStudy\WWW\ayu\test\\')
    {
        $redis = \app\common\library\Sign::getRedis();
        $key = '01.txt';
        $myfilecontent = $redis->get($key);
        $txt = "$content\n";
        $writeContent = $myfilecontent.$txt;
        $redis->set($key,$writeContent);
    }
}

if (!function_exists('debugtxtbase')){
    /**
     * @title 测试输出方法
     * @description 测试输出方法
     * @author Admin ldy
     * @param name:$content  type:string require:1 default:1 desc:内容
     * @time 2018/9/25  9:57
     * @param name:$name  type:string require:1 default:1 desc:文件名
     * @param name:$path  type:string require:1 default:1 desc: 路径
     */
    function debugtxtbase($content,$name,$path = 'F:\phpStudy\WWW\ayu\test\\')
    {
        $path = getpath();
        $myfile = fopen($path . $name . '.txt', 'w');
        $txt = "$content\n";
        fwrite($myfile, $txt);
        fclose($myfile);
    }
}


if (!function_exists('ly')){
    /**
     * @title 快捷打印调试
     * @description 快捷打印调试
     * @author Admin ldy
     * @param name:$arr  type:string require:1 default:1 desc:数组或字符串
     * @time 2018/9/25  10:01
     * @throws HttpException
     * @throws HttpResponseException
     */
    function ly($arr,$name=''){
        if (empty($name)){
            debugtxt(json_encode($arr));
        }else{
            debugtxtbase(json_encode($arr),$name);
        }
    }
}

if (!function_exists('object_array')){
    /**
     * @title json对象转标准数组
     * @description json对象转标准数组
     * @author Admin ldy
     * @param name:$jsonObject  type:string require:1 default:1 desc:json对象
     * @time 2018/9/25  9:59
     * @return array
     */
    function object_array($array){
        if(is_object($array)){
            $array = (array)$array;
        }
        if(is_array($array)){
            foreach($array as $key=>$value){
                $array[$key] = object_array($value);
            }
        }
        return $array;
    }
}

if (!function_exists('getpath')){
    /**
     * @title 根据环境获取不同的可写地址
     * @description
     * @author Admin ldy
     * @param name:$env  type:string require:1 default:1 desc:
     * @time 2018/11/7  17:58
     * @return string
     */
    function getpath(){
        $env = \think\facade\Config::get('scj.system_type');
        if ($env=='linux'){
            return \think\facade\App::getRuntimePath().'yulog/';
        }else{
            $path_windows = \think\facade\Config::get('scj.log_path_windows');
            return $path_windows;
        }
    }
}

if (!function_exists('httpcode')){

    function httpcode($url)
    {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_URL, $url);
        //忽略证书，不然的话https会返回0
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $httpcode;
    }
}